package com.androidbook.bro;

import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.Button;
import android.widget.TextView;

public class StartActivity extends Activity {

	int CurrentSum = 0;
	TextView ToWrite;
	Button BtnRight;
	Button BtnLeft;
	Button BtnUp;
	Button BtnMOVE;

	public int[] PressButton = { 0, 0, 0, 0 };

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.start);
		ToWrite = (TextView) findViewById(R.id.MyText);

		BtnRight = (Button) findViewById(R.id.btnRight);
		BtnLeft = (Button) findViewById(R.id.btnLeft);
		BtnUp = (Button) findViewById(R.id.btnUp);
		BtnMOVE = (Button) findViewById(R.id.btnDown);

		OnTouchListener l0 = new OnTouchListener(){
			public boolean onTouch(View v, MotionEvent event) {

				if (event.getAction() == MotionEvent.ACTION_MOVE) {
					PressButton[0] = 1;
					//PressChange();

				}

				if (event.getAction() == MotionEvent.ACTION_UP) {

					PressButton[0] = 0;
					//PressChange();

				}
				return true;
			}
		};
		OnTouchListener l1 = new OnTouchListener(){
			public boolean onTouch(View v, MotionEvent event) {

				if (event.getAction() == MotionEvent.ACTION_MOVE) {

					PressButton[1] = 1;
					//PressChange();

				}

				if (event.getAction() == MotionEvent.ACTION_UP) {

					PressButton[1] = 0;
					//PressChange();

				}
				return true;
			}
		};
		OnTouchListener l2 = new OnTouchListener(){
			public boolean onTouch(View v, MotionEvent event) {

				if (event.getAction() == MotionEvent.ACTION_MOVE) {
					PressButton[2] = 1;
					//PressChange();

				}

				if (event.getAction() == MotionEvent.ACTION_UP) {

					PressButton[2] = 0;
					//PressChange();

				}
				return true;
			}
		};
		OnTouchListener l3 = new OnTouchListener(){
			public boolean onTouch(View v, MotionEvent event) {

				if (event.getAction() == MotionEvent.ACTION_MOVE) {
					PressButton[0] = 1;
					//PressChange();

				}

				if (event.getAction() == MotionEvent.ACTION_UP) {

					PressButton[0] = 0;
					//PressChange();

				}
				return true;
			}
		};

		
		BtnLeft.setOnTouchListener(l0);
		BtnRight.setOnTouchListener(l1);
		BtnUp.setOnTouchListener(l2);
		BtnMOVE.setOnTouchListener(l3);
		
		PressChange thread = new PressChange(ToWrite,PressButton);
		thread.start();

	}

	public void PressChange() {
		ToWrite.setText(Integer.toString(PressButton[0])
				+ Integer.toString(PressButton[1])
				+ Integer.toString(PressButton[2])
				+ Integer.toString(PressButton[3]));
		

	}
}